package com.springboot.study.tests;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: guodong
 * @Date: 2022/1/8 14:39
 * @Version: 1.0
 * @Description:
 */
public class Sheep {

    boolean isAlive = true;
    Integer yearNum = 1;

    public void nextYear(List<Sheep> sheeps){
        yearNum++;
        if((yearNum == 6 || yearNum == 3) && isAlive){
            sheeps.add(new Sheep());
        }
        else if(yearNum >= 7){
            isAlive = false;
        }
    }


    public int afterNYearSheepNum(int n, List<Sheep> sheeps){
        for(int i=0;i<n;i++){
            List<Sheep> tmpSheeps = new ArrayList<>();
            sheeps.forEach((sheep)->{
                sheep.nextYear(tmpSheeps);
            });
            sheeps.addAll(tmpSheeps);
        }
        sheeps.removeIf((sheep)->!sheep.isAlive);
        return sheeps.size();
    }

    public static void main(String [] arg){
        List<Sheep> sheeps = new ArrayList<>();
        sheeps.add(new Sheep());
        int num = new Sheep().afterNYearSheepNum(6,sheeps);
        System.out.println(num);
    }


}
